﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LantinxLBS.Common;

namespace LantinxLBS.Views
{
    public partial class FrmWorkItemType : ChildWindow
    {
        public FrmWorkItemType()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(FrmWorkItemType_Loaded);
        }

        void FrmWorkItemType_Loaded(object sender, RoutedEventArgs e)
        {
            this.cmbWorkType.ItemsSource = ItemType.GetWorkItemType();
            this.cmbWorkLevel.ItemsSource = ItemType.GetWorkLevel();
            this.cmbWorkType.SelectedIndex = 0;
            this.cmbWorkLevel.SelectedIndex = 0;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            string workItemType = this.txtWorkItemType.Text.Trim();
            var itemType = this.cmbWorkType.SelectedValue as ItemType;
            var itemLevel = this.cmbWorkLevel.SelectedValue as ItemType;
            if (string.IsNullOrEmpty(workItemType))
            {
                MsgHelper.Show("任务类型不能为空");
            }
            else
            {
                DataHelper.SaveWorkItemType(workItemType, itemType.Value.ToString(), itemLevel.Value.ToString(), (result) =>
                {
                    this.Dispatcher.BeginInvoke(() =>
                        {
                            if (result)
                            {
                                this.DialogResult = true;
                            }
                        });
                });
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

    }
    public class ItemType
    {
        public String Name { get; set; }
        public int Value { get; set; }

        public static List<ItemType> GetWorkItemType()
        {
            List<ItemType> list = new List<ItemType>();
            list.Add(new ItemType() { Name = "定位", Value = 1 });
            list.Add(new ItemType() { Name = "拍照", Value = 2 });
            list.Add(new ItemType() { Name = "签到", Value = 3 });
            return list;
        }

        public static List<ItemType> GetWorkLevel()
        {
            List<ItemType> list = new List<ItemType>();
            list.Add(new ItemType() { Name = "每天必须完成", Value = 1 });
            list.Add(new ItemType() { Name = "临时任务", Value = 2 });
            return list;
        }
    }
}

